package com.jiantong.lawEnforcing.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 现场音影收集(记录现场收集的视频,照片,等)
 * Created by mz03 on 2017/8/25.
 */
@Data
public class SceneCollect implements Serializable{
    private static final long serialVersionUID = -6051148902347180208L;

    private static final ObjectMapper objectMapper= JsonMapper.nonEmptyMapper().getMapper();
    /**
     * 主键id
     */
    private Long id;


    /**
     * 对应案件基础信息ID(登记案件ID)
     */
    private Long cases_basic_id;


    /**
     *照片 photo_json
     * picture_map
     */
    @JsonIgnore
    private String picture_map;


    /**
     * 不存数据库
     */
    private Map<String , Map<String , String>> photoMap;


    /**
     *视频 video_json
     * video_map
     */
    @JsonIgnore
    private String video_map;



    /**
     * 视频map
     * videos
     */
    private Map<String , String> videos;


    /**
     *视频图片  不存数据库
     */
    private Map<String , Map<String , String>> videoPhotoMap;

    /**
     *视频图片 video_photo_json
     */
    @JsonIgnore
    private String video_photo_json;


    /**
     * 定位信息经度
     */
    private String longitude;


    /**
     * 定位信息纬度
     */
    private String latitude;


    /**
     * 详细信息
     */
    private String address;


    /**
     * 备注
     */
    private String remark;


    /**
     * 1：正常，-1：删除
     */
    private Integer delete_flag;


    /**
     * 创建时间
     */
    private Date created_at;


    /**
     * 更新时间
     */
    private Date update_at;

//------------------------------------------------------------------------------

    public void setPicture_map(String picture_map){
        this.picture_map = picture_map;
        if(Strings.isNullOrEmpty(picture_map)){
            this.photoMap = Maps.newHashMap();;
        }else {
            try {
                this.photoMap = objectMapper.readValue(picture_map, new TypeReference<Map<String , Map<String , String>>>(){});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setPhotoMap(Map<String , Map<String , String>> photoMap){
        this.photoMap = photoMap;
        if(photoMap == null || photoMap.isEmpty()){
            this.picture_map = null;
        }else {
            try {
                this.picture_map = objectMapper.writeValueAsString(photoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck IOException
            }
        }
    }
    public void setVideo_map(String video_map){
        this.video_map = video_map;

        if(Strings.isNullOrEmpty(video_map)){
            this.videos = Maps.newHashMap();
        }else {
            try {
                this.videos = objectMapper.readValue(video_map, new TypeReference<Map<String , String>>() {});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setVideos(Map<String , String> videos){
        this.videos = videos;

        if(videos == null || videos.isEmpty()){
            this.video_map = null;
        }else {
            try {
                this.video_map = objectMapper.writeValueAsString(videos);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }

    public void setVideo_photo_json(String video_photo_json){
        this.video_photo_json = video_photo_json;

        if(Strings.isNullOrEmpty(video_photo_json)){
            this.videoPhotoMap = Maps.newHashMap();
        }else {
            try {
                this.videoPhotoMap = objectMapper.readValue(video_photo_json, new TypeReference<Map<String , Map<String , String>>>() {});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setVideoPhotoMap(Map<String , Map<String , String>> videoPhotoMap){
        this.videoPhotoMap = videoPhotoMap;

        if(videoPhotoMap == null || videoPhotoMap.isEmpty()){
            this.video_photo_json = null;
        }else {
            try {
                this.video_photo_json= objectMapper.writeValueAsString(videoPhotoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }

/*


    public void setPictures(List<String> pictures){
        this.pictures = pictures;
        if(pictures == null || pictures.isEmpty()){
            this.picture_map = null;
        }else {
            try {
                this.picture_map =
                        objectMapper.writeValueAsString(pictures);
            } catch (JsonProcessingException e) {
                //this is fuck exception
            }
        }
    }


    public void setPicture_map(String picture_map){
        this.picture_map = picture_map;

        if(Strings.isNullOrEmpty(picture_map)){
            this.pictures = new ArrayList<>();
        }else {
            try {
                this.pictures =
                        objectMapper.readValue(picture_map, new TypeReference<List<String>>() {});
            } catch (IOException e) {
                //this is fuck exception
            }
        }
    }


    public void setVideos(List<String> videos){
        this.videos = videos;
        if(videos == null || videos.isEmpty()){
            this.video_map = null;
        }else {
            try {
                this.video_map =
                        objectMapper.writeValueAsString(videos);
            } catch (JsonProcessingException e) {
                //this is fuck exception
            }
        }
    }


    public void setEarNumberJson(String earNumberJson){
        this.video_map = earNumberJson;

        if(Strings.isNullOrEmpty(earNumberJson)){
            this.videos = new ArrayList<>();
        }else {
            try {
                this.videos =
                        objectMapper.readValue(earNumberJson, new TypeReference<List<String>>() {});
            } catch (IOException e) {
                //this is fuck exception
            }
        }
    }
*/


}
